#include "onewindow.h"
#include "build/Desktop_Qt_6_8_0_MinGW_64_bit-Debug/ui_onewindow.h"
#include "ui_onewindow.h"

int RSA(int c);
int AES(int a,int b);
int Caser(int a,int b);

int fun=0;
int plaintext=0;
int secretkey=0;

oneWindow::oneWindow(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::oneWindow)
{
    ui->setupUi(this);
}

oneWindow::~oneWindow()
{

}

void oneWindow::paintEvent(QPaintEvent *event)
{
    QPainter painter(this);
    painter.drawPixmap(0,0,width(),height(),QPixmap(":/background/background.jpg"));

}

void oneWindow::on_AES_clicked(bool checked)
{
    ui->inputtitle->setText("Input yout text of AES:");
    ui->input1->show();
    ui->input2->show();
    fun=1;
}

void oneWindow::on_RSA_clicked(bool checked)
{
    ui->inputtitle->setText("Input yout text of RSA：");
    ui->input1->show();
    ui->input2->hide();
    fun=2;
}

void oneWindow::on_Caser_clicked(bool checked)
{
    ui->inputtitle->setText("Input yout text of Caser：");
    ui->input1->show();
    ui->input2->show();
    fun=3;
}

void oneWindow::on_input1_editingFinished()
{
    QString inputText = ui->input1->text();
    // 将输入转换为整数
    plaintext = inputText.toInt();
}

void oneWindow::on_input2_editingFinished()
{
    QString inputText = ui->input2->text();
    // 将输入转换为整数
    secretkey = inputText.toInt();
}

void oneWindow::on_pushButton_clicked()
{
    int ciphertext;
    switch (fun) {
    case 1:
        ciphertext = AES(plaintext,secretkey);
        break;
    case 2:
        ciphertext = RSA(plaintext);
        break;
    case 3:
        ciphertext = Caser(plaintext,secretkey);
    default:
        break;
    }
    ui->output->setText(QString::number(ciphertext));
}




